package com.gxuwz.medical.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.gxuwz.medical.database.DbUtil;
import com.gxuwz.medical.domain.user.User;
import com.mysql.jdbc.PreparedStatement;

public class UserDao {
	DbUtil Db = new DbUtil();
	private Connection conn = null;
	private PreparedStatement stmt = null;
	private ResultSet rs = null;
	public User user(String userid)throws SQLException{
		Connection conn = Db.getConn();
		String sql ="select * from User where userid = '"+userid+"'";
		java.sql.PreparedStatement stmt = conn.prepareStatement(sql);
		ResultSet rs = stmt.executeQuery();
		while (rs.next()) {
			User user = new User();
			user.setUserid(rs.getString("userid"));
			user.setPwd(rs.getString("pwd"));
			user.setFullname(rs.getString("fullname"));
			
			return user;
		}
		conn.close();
		return null;
	}
	public User userAdd(String userid,String pwd,String fullname)throws SQLException{
		Connection conn = Db.getConn();
		java.sql.PreparedStatement stmt = null;
		try {

			String sql = "insert into User(userid,pwd,fullname)"+"values('"+userid+"','"+pwd+"','"+fullname+"')";
	
			stmt = conn.prepareStatement(sql);
			stmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return null;
		}

}

